package com.bw.zhuangao5___day002.Fragment.Movies;

import android.content.Context;
import android.content.Intent;
import android.graphics.Outline;
import android.view.View;
import android.view.ViewOutlineProvider;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.bw.mvp.V.BannerFragment;
import com.bw.zhuangao5___day002.Fragment.Movies.One.Day1.MoviesOneDay1_Activity;
import com.bw.zhuangao5___day002.Fragment.Movies.One.Day2.MoviesOneDay2_Activity;
import com.bw.zhuangao5___day002.Fragment.Movies.One.Day3.MoviesOneDay3_Activity;
import com.bw.zhuangao5___day002.Fragment.Movies.One.MoviesOne_Adoter;
import com.bw.zhuangao5___day002.Fragment.Movies.One.MoviesOne_Contion;
import com.bw.zhuangao5___day002.Fragment.Movies.One.MoviesOne_JavaBen;
import com.bw.zhuangao5___day002.Fragment.Movies.One.MoviesOne_Model;
import com.bw.zhuangao5___day002.Fragment.Movies.One.MoviesOne_Pretenter;
import com.bw.zhuangao5___day002.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.listener.OnItemChildLongClickListener;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;


public class BlankFragmentMoviesOne extends BannerFragment implements MoviesOne_Contion.oneview, OnRefreshLoadMoreListener, OnItemChildClickListener, OnItemChildLongClickListener {


    public int butaty = 0;
    public MoviesOne_Pretenter moviesOne_pretenter;
    public int pash = 1;
    public boolean isone = true;
    public MoviesOne_Adoter adoter;
    private SmartRefreshLayout MoviesOneSmart;
    List<MoviesOne_JavaBen.DataBean> listha;
    private RecyclerView MoviesOneView;
    private Banner MoviesOneBanner;

    @Override
    public int bandLayoud() {
        return R.layout.fragment_blank_fragment_movies_one;
    }

    @Override
    public void initView() {
        MoviesOneBanner = (Banner) findViewById(R.id.MoviesOne_banner);
        MoviesOneSmart = (SmartRefreshLayout) findViewById(R.id.MoviesOne_smart);
        MoviesOneView = (RecyclerView) findViewById(R.id.MoviesOne_view);
        MoviesOneSmart.setOnRefreshLoadMoreListener(this);
        MoviesOneView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
        moviesOne_pretenter = new MoviesOne_Pretenter(this, new MoviesOne_Model());
        moviesOne_pretenter.dogetmoviesone("dish_list.php?stage_id=1&limit=30&page=" + pash + "");

    }

    @Override
    public void initDate() {

        listha = new ArrayList<>();
        MoviesOneBanner.setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 50);
            }
        });

        MoviesOneBanner.setClipToOutline(true);


    }

    @Override
    public void getoneview(List<MoviesOne_JavaBen.DataBean> dataBeans) {
        listha = dataBeans;
        MoviesOneSmart.finishLoadMore();
        MoviesOneSmart.finishRefresh();
        for (MoviesOne_JavaBen.DataBean dataBean : dataBeans) {
            dataBean.setTatylayoutione(++butaty);
            if (butaty == 3) {
                butaty = 0;
            }
        }

        if (adoter == null) {
            adoter = new MoviesOne_Adoter(dataBeans);
            adoter.setOnItemChildClickListener(this);
            adoter.setOnItemChildLongClickListener(this);
            MoviesOneView.setAdapter(adoter);
        } else {
            if (isone) {
                adoter.getData().clear();
            }
            adoter.getData().addAll(dataBeans);
            adoter.notifyDataSetChanged();
        }


        MoviesOneBanner.setImages(dataBeans);
        MoviesOneBanner.setBannerAnimation(Transformer.CubeOut);//------设置动画效果
        MoviesOneBanner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);//------类型
        MoviesOneBanner.setImageLoader(new ImageLoader() {
            @Override
            public void displayImage(Context context, Object path, ImageView imageView) {
                MoviesOne_JavaBen.DataBean list = (MoviesOne_JavaBen.DataBean) path;
                Glide.with(context).load(list.getPic()).into(imageView);
            }
        }).start();
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        if (isone){
            pash=1;
        }
        moviesOne_pretenter.dogetmoviesone("dish_list.php?stage_id=1&limit=30&page="+pash+"");
    }



    @Override
    public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
        switch (view.getId())
        {
            case R.id.moviesoneadpter1_Img:
                Intent intent1 = new Intent(getActivity(), MoviesOneDay1_Activity.class);
                startActivity(intent1);
                break;

            case R.id.moviesoneadpter2_Img:
                Intent intent2 = new Intent(getActivity(), MoviesOneDay2_Activity.class);
                startActivity(intent2);
                break;

            case R.id.moviesoneadpter3_Img:
                Intent intent3 = new Intent(getActivity(), MoviesOneDay3_Activity.class);
                intent3.putExtra("name",listha.get(position).getTitle());
                intent3.putExtra("pic",listha.get(position).getPic());
                intent3.putExtra("stringnum",listha.get(position).getCollect_num());
                intent3.putExtra("cailiao",listha.get(position).getFood_str());
                intent3.putExtra("num",listha.get(position).getNum());
                startActivity(intent3);
                break;
        }
    }

    @Override
    public boolean onItemChildLongClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
        switch (view.getId())
        {
            case R.id.moviesoneadpter1_Img:
                ToastUtils.showShort("喜欢就看看吧");
                break;

            case R.id.moviesoneadpter2_Img:
                ToastUtils.showShort("喜欢就来看看吧");
                break;

            case R.id.moviesoneadpter3_Img:
                ToastUtils.showShort("喜欢就进来看看吧");
                break;
        }
        return true;
    }
}
